var express = require('express');
var bodyParser = require('body-parser');
var request = require('request');
var app = express();
app.use(function(req, res, next) {
    //允许跨域
    res.header("Access-Control-Allow-Origin", "*");
    next();
});
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
//获取新闻详情
app.get('/getnewsdetail', function(req, res) {
    var url = `http://39.108.173.168:8888/api/news/get?id=${req.query.id}`;
    request(url, function(err, response, body) {
        res.send({ data: JSON.parse(body.toString()) });
    });
});
//获取新闻评论
app.get('/getnewscomments', function(req, res) {
    var url = `http://39.108.173.168:8888/api/news/review?id=${req.query.id}&pageNum=${req.query.pageNum}`;
    request(url, function(err, response, body) {
        res.send({ data: JSON.parse(body.toString()) });
    });
});
app.listen(3000, function() {
    console.log('start at http://127.0.0.1:3000');
});